/**
 * @name variable-subscript search
 * @id python/variable-addon-search
 */

import python
import util

string addon2string(Expr expr)
{
    if expr instanceof Attribute then
        result=addon2string(expr.(Attribute).getObject())+"."+expr.(Attribute).getName()
    else if expr instanceof Subscript then
        result=addon2string(expr.(Subscript).getObject())+"["+expr.(Subscript).getIndex()+"]"
    else
        result=expr2string(iterExpr(expr))
}

from File f,Module mod,Scope scope,string scopeName,Subscript expr,Expr object,Expr index,string indexName,string objName,Location location,Location indexLocation,string loc,string indexLoc
where
//debug(location) and
isSource(f) and
scope=expr.getScope() and
mod=scope.getEnclosingModule() and
f=mod.getFile() and
object=iterExpr(expr.getObject()) and
index=iterExpr(expr.getIndex()) and
indexName=expr2string(index) and
objName=expr2string(object) and
//f.getAbsolutePath()="/opt/src/pro/builders/optimizer_builder.py" and
location=object.getLocation() and
indexLocation=index.getLocation() and
loc=getLocText(location) and
indexLoc=getLocText(indexLocation) and
scopeName=getScopeName(scope)
select f,mod,scope,objName,indexName,expr,scopeName,loc,indexLoc